<template>
  优惠券标题<input type="text" v-model="prist.title">库存数量<input type="text" v-model="prist.kcount">
  开始时间<input type="date" v-model="prist.sdate">结束时间<input type="date" v-model="prist.edate">
  <input type="button" value="查询" @click="getMaxLis">
    <table>
      <tr>
        <td><input type="checkbox" value=""></td>
        <td>优惠券类型</td>
        <td>优惠券标题</td>
        <td>库存数量</td>
        <td>开始时间</td>
        <td>结束时间</td>
        <td>备注</td>
        <td>状态</td>
        <td>操作</td>
      </tr>
      <tr v-for="item in list">
        <td><input type="checkbox" value=""></td>
        <td>{{ item.dtname }}</td>
        <td>{{item.dtitle}}</td>
        <td>{{ item.number }}</td>
        <td>{{item.starttime.substr(0,10)}}</td>
        <td>{{item.endtime.substr(0,10)}}</td>
        <td>{{item.desc}}</td>
        <td>{{item.dstates==1?"启用":"禁用"}}</td>
        <td><input type="button" value="OFF/ON" @click="updstetas(item.did,item.dstates)"><input type="button" value="修改" @click="uopdatek(item.did)"></td>
      </tr>
    </table>
    共<span style="color: red;">{{ count }}</span>条,每页<span style="color: red;">{{ prist.page }}</span>条,当前<span style="color: red;">{{ prist.index }}</span>/<span style="color: red;">{{ pcount }}</span>页
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    list:[],
    prist:{
      title:'',
      kcount:'',
      sdate:'',
      edate:'',
      index:1,
      page:2
    },
    count:0,
    pcount:0
  })
  let {prist,list,count,pcount} =toRefs(data)

  onMounted(()=>{
    getMaxLis()
  })

  const getMaxLis=()=>{
    let obj={
      title:prist.value.title,
      kcount:prist.value.kcount,
      startdate:prist.value.sdate,
      enddate:prist.value.edate,
      index:prist.value.index,
      page:prist.value.page
    }
    axios({
      url:'/api/Mem/Getdiscou',
      method:'get',
      params:obj
    })
    .then(res=>{
      list.value=res.data.data;
      count=res.data.coco;
      pcount=res.data.promax;
    })
  }

  const updstetas=(did:any,dstates:any)=>{
    if(dstates==1){
      dstates=0;
    }else{
      dstates=1;
    }
    let obj={
      did:did,
      states:dstates
    }
    console.log(obj)
    axios({
      url:'/api/Mem/Updsates',
      method:'get',
      params:obj
    })
    .then(res=>{
      console.log(res)
      if(res.data.data==1){
        alert("修改按钮成功")
        getMaxLis()
      }else{
        alert("修改按钮失败")
      }
    })
  }

  const uopdatek=(did:any)=>{
    router.push('upddis')
    route.query.did
  }

  </script>
  
  <style scoped>
  
  </style>